﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - EvaluateComment" 
*/ 

component 
	displayname="public.service.db.senate.sequence.EvaluateComment" 
	output=false 
	accessors=true 
	{
	
	property type="string" name="TermID" hint="学期代码";
	property type="string" name="StudentID" hint="学号";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = getTermID() & "," & getStudentID() & "," & numberFormat(1, "0__");
		
		/* 
			主键生成规则 VARCHAR(28)
			
			3位学期 , 20位学号 , 3位流水号
		*/
		
		var sql = "SELECT msg_id FROM t_evaluate_comment 
					WHERE 
						term_id = :termId AND stu_id = :studentId 
					ORDER BY msg_id DESC ";
		
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		
		queryObj.addParam( name="termId", value=getTermID(), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="studentId", value=getStudentID(), cfsqltype="cf_sql_varchar" );

		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_check.recordCount ) {
			/* 创建一个追加id */
			nextID = getTermID() & "," & getStudentID() & "," & numberFormat( ( right( rs_check.msg_id, 3 ) + 1 ), "0__");
		}

		return nextID;
		
	}
	
}
		
</cfscript>